home *** CD-ROM | disk | FTP | other *** search
- onClipEvent(enterFrame){
- var INITIAL_HIT_BOUNCE_DELTA_Y = 8;
- var BOUNCE_DROP_SPEED = -1.8;
- switch(_parent.gamestate)
- {
- case GAMESTATE_PAUSED:
- grabtime();
- if(!Key.isDown(32) && !Key.isDown(80))
- {
- _parent.gamestate = GAMESTATE_PAUSED_WAIT;
- }
- break;
- case GAMESTATE_PAUSED_WAIT:
- grabtime();
- if(Key.isDown(32) || Key.isDown(80))
- {
- _parent.gamestate = GAMESTATE_PLAYING_WAIT;
- mouse.hide();
- }
- break;
- case GAMESTATE_PLAYING:
- case GAMESTATE_PLAYING_WAIT:
- timeinstate += _parent.delta;
- grabtime();
- var a = 0;
- while(a < animations.length)
- {
- animations[a][ANIMATION_FRAMETIME] += _parent.delta * animations[a][ANIMATION_SPEED];
- if(animations[a][ANIMATION_FRAMETIME] > 1)
- {
- animations[a][ANIMATION_CURRENT_FRAME]++;
- if(animations[a][ANIMATION_CURRENT_FRAME] > animations[a][ANIMATION_END_FRAME])
- {
- animations[a][ANIMATION_CURRENT_FRAME] = animations[a][ANIMATION_START_FRAME];
- }
- animations[a][ANIMATION_FRAMETIME] -= 1;
- }
- a++;
- }
- if(chewystate == CHEWY_STATE_FIRING)
- {
- var a = FIRE_IDLE_ANIMATION;
- while(a <= FIRE_WALK_ANIMATION)
- {
- animations[a][ANIMATION_FRAMETIME] += _parent.delta;
- if(animations[a][ANIMATION_FRAMETIME] > 1)
- {
- animations[a][ANIMATION_CURRENT_FRAME]++;
- if(animations[a][ANIMATION_CURRENT_FRAME] > animations[a][ANIMATION_END_FRAME])
- {
- timeinstate = 0;
- chewystate = CHEWY_STATE_OK;
- animations[a][ANIMATION_CURRENT_FRAME] = animations[a][ANIMATION_START_FRAME];
- }
- animations[a][ANIMATION_FRAMETIME] = 0;
- }
- a++;
- }
- }
- var CHEW_TIME = 12;
- if(chewystate == CHEWY_STATE_CHEWING && timeinstate > CHEW_TIME)
- {
- timeinstate = 0;
- chewystate = CHEWY_STATE_OK;
- }
- switch(chewystate)
- {
- case CHEWY_STATE_OK:
- case CHEWY_STATE_CHEWING:
- case CHEWY_STATE_FIRING:
- var b = 0;
- while(b < MAX_BAGS)
- {
- if(_parent["bag" + b]._visible)
- {
- if(_parent["bag" + b].canhitchewy && bagcollison(b))
- {
- play_chewyhitbybag_sound();
- chewystate = CHEWY_STATE_HIT;
- var CHEWY_BOUNCE_DELTA_X = 6;
- if(_parent["bag" + b]._x > _X)
- {
- chewy_facing = CHEWY_FACING_LEFT;
- delta_x = - CHEWY_BOUNCE_DELTA_X;
- }
- else
- {
- chewy_facing = CHEWY_FACING_RIGHT;
- delta_x = CHEWY_BOUNCE_DELTA_X;
- }
- delta_y = INITIAL_HIT_BOUNCE_DELTA_Y;
- initial_delta_y = INITIAL_HIT_BOUNCE_DELTA_Y;
- bounce_speed = BOUNCE_DROP_SPEED;
- timeinstate = 0;
- _parent["bag" + b]._visible = false;
- nobags--;
- lives--;
- if(lives >= 0)
- {
- _parent["life" + lives]._visible = false;
- }
- var b2 = 0;
- while(b2 < MAX_BAGS)
- {
- if(_parent["bag" + b2]._visible)
- {
- _parent["bag" + b2].canhitchewy = false;
- }
- b2++;
- }
- }
- var FLAME_WIDTH = 9;
- var f = 0;
- while(f < MAX_FLAMES)
- {
- if(_parent["flame" + f]._visible)
- {
- if(_parent["bag" + b].hittest(_parent["flame" + f]._x - FLAME_WIDTH,_parent["flame" + f]._y) || _parent["bag" + b].hittest(_parent["flame" + f]._x + FLAME_WIDTH,_parent["flame" + f]._y))
- {
- play_baghitbyfireball_sound();
- var TOP_TIME = 10;
- var distancescale = _parent["flame" + f].flametime / TOP_TIME;
- if(distancescale > 1)
- {
- distancescale = 1;
- }
- throwchewits(b,distancescale);
- _parent["bag" + b]._visible = false;
- _parent["flame" + f]._visible = false;
- nobags--;
- }
- }
- f++;
- }
- }
- b++;
- }
- nextflametime -= _parent.delta;
- var REENABLE_BAGS_TIME = 12;
- if(timeinstate > REENABLE_BAGS_TIME && timeinstate < REENABLE_BAGS_TIME + 0.3)
- {
- var b = 0;
- while(b < MAX_BAGS)
- {
- if(!_parent["bag" + b].canhitchewy)
- {
- _parent["bag" + b].canhitchewy = true;
- }
- b++;
- }
- }
- var desired_x = _parent._xmouse;
- MOVERATE = 15;
- if(_X <= desired_x)
- {
- if(desired_x > MAX_X - CHEWY_WIDTH / 2)
- {
- desired_x = MAX_X - CHEWY_WIDTH / 2;
- }
- _X = _X + MOVERATE * _parent.delta;
- if(_X >= desired_x)
- {
- _X = desired_x;
- }
- }
- if(_X > desired_x)
- {
- if(desired_x < MIN_X + CHEWY_WIDTH / 2)
- {
- desired_x = MIN_X + CHEWY_WIDTH / 2;
- }
- _X = _X - MOVERATE * _parent.delta;
- if(_X < desired_x)
- {
- _X = desired_x;
- }
- }
- var MOUTHDISTANCE_X = 12;
- var MOUTHDISTANCE_Y = 24;
- var mouthposition_x = _X;
- var mouthposition_y = _Y - MOUTHDISTANCE_Y - CHEWY_Y_ADJUST;
- if(chewyfacing == CHEWY_FACING_LEFT)
- {
- mouthposition_x -= MOUTHDISTANCE_X;
- }
- else
- {
- mouthposition_x += MOUTHDISTANCE_X;
- }
- var onesuckedin = 0;
- var c = 0;
- while(c < MAX_CHEWITS)
- {
- if(_parent["chewit" + c]._visible)
- {
- if(_parent["chewit" + c].suckedin)
- {
- _parent["chewit" + c].sucktime += _parent.delta;
- onesuckedin = 1;
- _parent["chewit" + c]._x += mouthposition_x - _parent["chewit" + c].last_mx;
- _parent["chewit" + c]._y += mouthposition_y - _parent["chewit" + c].last_my;
- }
- var dist_x = mouthposition_x - _parent["chewit" + c]._x;
- var dist_y = mouthposition_y - _parent["chewit" + c]._y;
- var thisdistance = dist_x * dist_x + dist_y * dist_y;
- if(_parent["chewit" + c].suckedin)
- {
- var MOVE_SCALE = 0.4;
- _parent["chewit" + c]._x += dist_x * _parent.delta * MOVE_SCALE;
- _parent["chewit" + c]._y += dist_y * _parent.delta * MOVE_SCALE;
- _parent["chewit" + c].last_mx = mouthposition_x;
- _parent["chewit" + c].last_my = mouthposition_y;
- _parent["chewit" + c]._rotation += _parent["chewit" + c].rotaterate * _parent.delta;
- var scalechew = CHEWIT_SCALE * thisdistance / _parent["chewit" + c].suck_distance;
- if(scalechew > CHEWIT_SCALE)
- {
- scalechew = CHEWIT_SCALE;
- }
- _parent["chewit" + c]._xscale = scalechew;
- _parent["chewit" + c]._yscale = scalechew;
- var MAX_SUCK_TIME = 2;
- if(scalechew < 4 || _parent["chewit" + c].sucktime < MAX_SUCK_TIME)
- {
- play_chewyeatsachewit_sound();
- var points = getpoints();
- var combono = 0;
- var c2 = 0;
- while(c2 < MAX_CHEWITS)
- {
- if(c != c2 && _parent["chewitscore" + c2]._visible && !_parent["chewitscore" + c2].bombshot)
- {
- combono++;
- }
- c2++;
- }
- score += points * (1 + combono);
- addchewitscore(c,points * (1 + combono),combono);
- updatescore(score);
- _parent["chewit" + c]._visible = false;
- _parent["chewitscore" + c].bombshot = false;
- }
- }
- else
- {
- var CHOMP_TOLERANCE_X2 = 1024;
- var CHOMP_TOLERANCE_Y2 = 144;
- var distancex = _parent["chewit" + c]._x - mouthposition_x;
- var distancey = _parent["chewit" + c]._y - mouthposition_y;
- var distancex2 = distancex * distancex;
- var distancey2 = distancey * distancey;
- if(distancex2 < CHOMP_TOLERANCE_X2 && distancey2 < CHOMP_TOLERANCE_Y2)
- {
- var SWALLOW_ROTATE_RATE = 10;
- _parent["chewit" + c].suckedin = true;
- _parent["chewit" + c].sucktime = 0;
- _parent["chewit" + c].suck_distance = thisdistance;
- _parent["chewit" + c].last_mx = mouthposition_x;
- _parent["chewit" + c].last_my = mouthposition_y;
- if(_parent["chewit" + c].rotaterate > 0)
- {
- _parent["chewit" + c].rotaterate = SWALLOW_ROTATE_RATE;
- }
- else
- {
- _parent["chewit" + c].rotaterate = - SWALLOW_ROTATE_RATE;
- }
- chewystate = CHEWY_STATE_CHEWING;
- timeinstate = 0;
- }
- }
- }
- c++;
- }
- WALK_TOLERANCE = 4;
- if(Math.abs(lastwalkpos - _X) > WALK_TOLERANCE)
- {
- if(lastwalkpos > _X)
- {
- chewyfacing = CHEWY_FACING_RIGHT;
- }
- else
- {
- chewyfacing = CHEWY_FACING_LEFT;
- }
- lastwalkpos = _X;
- if(chewystate == CHEWY_STATE_CHEWING)
- {
- this.gotoAndStop(animations[CHEW_WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- else if(chewystate == CHEWY_STATE_FIRING)
- {
- this.gotoAndStop(animations[FIRE_WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- else if(onesuckedin == 1)
- {
- this.gotoAndStop(animations[SUCK_WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- else
- {
- this.gotoAndStop(animations[WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- }
- else if(chewystate == CHEWY_STATE_CHEWING)
- {
- this.gotoAndStop(animations[CHEW_IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- else if(chewystate == CHEWY_STATE_FIRING)
- {
- this.gotoAndStop(animations[FIRE_IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- else if(onesuckedin == 1)
- {
- this.gotoAndStop(animations[SUCK_IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- else
- {
- this.gotoAndStop(animations[IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
- }
- break;
- case CHEWY_STATE_HIT:
- this.gotoAndStop(animations[HIT_ANIMATION][ANIMATION_CURRENT_FRAME]);
- delta_y += bounce_speed * _parent.delta;
- _Y = _Y - delta_y * _parent.delta;
- _X = _X + delta_x * _parent.delta;
- if(_X > MAX_X - CHEWY_WIDTH / 2)
- {
- _X = MAX_X - CHEWY_WIDTH / 2;
- delta_x = 0;
- }
- if(_X < MIN_X + CHEWY_WIDTH / 2)
- {
- _X = MIN_X + CHEWY_WIDTH / 2;
- delta_x = 0;
- }
- if(_Y > base_y)
- {
- _Y = base_y;
- initial_delta_y /= 2;
- if(initial_delta_y > INITIAL_HIT_BOUNCE_DELTA_Y / 16)
- {
- delta_y = initial_delta_y;
- }
- else
- {
- delta_y = 0;
- bounce_speed = 0;
- }
- }
- if(timeinstate > HIT_TIME_MAXIMUM)
- {
- _Y = base_y;
- _alpha = 100;
- timeinstate = 0;
- if(lives < 0)
- {
- play_death_sound();
- _parent.gamestate = GAMESTATE_GAME_OVER_FADE;
- }
- else
- {
- chewystate = CHEWY_STATE_OK;
- }
- }
- else
- {
- var segment = Math.round(timeinstate * 10 / HIT_TIME_MAXIMUM);
- if(segment % 2 == 1)
- {
- _alpha = 0;
- }
- else
- {
- _alpha = 100;
- }
- }
- }
- if(chewyfacing == CHEWY_FACING_LEFT)
- {
- _xscale = CHEWY_SCALE;
- }
- else
- {
- _xscale = - CHEWY_SCALE;
- }
- updatebags();
- updatebomb();
- updateflames();
- updatechewits();
- updatefloor();
- if(_parent.gamestate == GAMESTATE_PLAYING)
- {
- if(Key.isDown(32) || Key.isDown(80))
- {
- _parent.gamestate = GAMESTATE_PAUSED;
- mouse.show();
- }
- }
- else if(_parent.gamestate == GAMESTATE_PLAYING_WAIT)
- {
- if(!Key.isDown(32) && !Key.isDown(80))
- {
- _parent.gamestate = GAMESTATE_PLAYING;
- }
- }
- var FLOOR_MAXIMUM_HEIGHT = 130;
- if(base_y < FLOOR_MAXIMUM_HEIGHT)
- {
- if(base_y >= FLOOR_MAXIMUM_HEIGHT)
- {
- score = Math.floor(300 * Math.random()) * 10;
- updatescore();
- }
- play_chewyhitsthetop_sound();
- lives = 0;
- _parent.gamestate = GAMESTATE_GAME_OVER_FADE;
- timeinstate = 0;
- _parent.life0._visible = false;
- _parent.life1._visible = false;
- _parent.life2._visible = false;
- }
- break;
- case GAMESTATE_GAME_OVER_FADE:
- if(_parent.floorsoundplaying)
- {
- stop_floorraising_noise();
- _parent.floorsoundplaying = false;
- }
- timeinstate += _parent.delta;
- var fadeamount = 100 - 100 * timeinstate / 20;
- if(fadeamount < 0)
- {
- fadeamount = 0;
- }
- _alpha = fadeamount;
- var b = 0;
- while(b < MAX_BAGS)
- {
- _parent["bag" + b]._alpha = fadeamount;
- b++;
- }
- var f = 0;
- while(f < MAX_FLAMES)
- {
- _parent["flame" + f]._alpha = fadeamount;
- f++;
- }
- var c = 0;
- while(c < MAX_CHEWITS)
- {
- _parent["chewit" + c]._alpha = fadeamount;
- _parent["chewitscore" + c]._alpha = _parent["chewitscore" + c].startalpha * fadeamount / 100;
- c++;
- }
- _parent.comboscore._alpha = _parent.comboscore.startalpha * fadeamount / 100;
- _parent.bonusbomb._alpha = _parent.bonusbomb.startalpha * fadeamount / 100;
- if(fadeamount == 0)
- {
- mouse.show();
- _parent.gamestate = GAMESTATE_GAME_OVER_HISCORE_ENTRY;
- timeinstate = 0;
- _parent.scoretext._visible = false;
- _parent.floor_mc._visible = false;
- _parent.sky_mc._visible = false;
- }
- break;
- case GAMESTATE_GAME_OVER_HISCORE_ENTRY:
- _parent.attachMovie("hiscoreentry_mc","hiscoreentry",40);
- _parent.hiscoreentry.myname.text = "";
- _parent.gamestate = GAMESTATE_GAME_OVER;
- timeinstate = 0;
- break;
- case GAMESTATE_GAME_OVER_HISCORES:
- var thename = _parent.hiscoreentry.myname.text;
- _parent.attachMovie("hiscorescreen_mc","hiscorescreen",40);
- _parent.hiscorescreen._x = 0;
- _parent.hiscorescreen._y = 0;
- _parent.hiscorescreen._visible = true;
- var HISCORE_START_X = 38;
- var HISCORE_START_Y = 107;
- var HISCORE_DELTA_Y = 30;
- var MAX_HIGHSCORES = 10;
- var h = 0;
- while(h < MAX_HIGHSCORES)
- {
- _parent.hiscorescreen.attachMovie("highscore_mc","hiscore" + h,42 + h);
- _parent.hiscorescreen["hiscore" + h]._x = HISCORE_START_X;
- _parent.hiscorescreen["hiscore" + h]._y = HISCORE_START_Y + HISCORE_DELTA_Y * h;
- _parent.hiscorescreen["hiscore" + h].score.text = hiscores[h][1];
- if(hiscores[h][0] != "")
- {
- _parent.hiscorescreen["hiscore" + h].position.text = h + 1 + ".";
- }
- else
- {
- _parent.hiscorescreen["hiscore" + h].position.text = "";
- }
- _parent.hiscorescreen["hiscore" + h].name.text = hiscores[h][0];
- _parent.hiscorescreen["hiscore" + h].score.embedFonts = true;
- _parent.hiscorescreen["hiscore" + h].name.embedFonts = true;
- _parent.hiscorescreen["hiscore" + h].position.embedFonts = true;
- h++;
- }
- var YOUR_SCORE_GAP = 9;
- _parent.hiscorescreen.attachMovie("highscore_mc","hiscore-1",41);
- _parent.hiscorescreen["hiscore-1"]._x = HISCORE_START_X;
- _parent.hiscorescreen["hiscore-1"]._y = HISCORE_START_Y + HISCORE_DELTA_Y * hiscores.length + YOUR_SCORE_GAP;
- if(thename == "")
- {
- thename = "(you)";
- }
- _parent.hiscorescreen["hiscore-1"].position.text = positiontext;
- myformat1 = _parent.hiscorescreen["hiscore-1"].position.getTextFormat();
- myformat1.color = 65535;
- _parent.hiscorescreen["hiscore-1"].position.embedFonts = true;
- _parent.hiscorescreen["hiscore-1"].position.setTextFormat(myformat1);
- _parent.hiscorescreen["hiscore-1"].position.embedFonts = true;
- _parent.hiscorescreen["hiscore-1"].name.text = thename;
- myformat1 = _parent.hiscorescreen["hiscore-1"].name.getTextFormat();
- myformat1.color = 65535;
- _parent.hiscorescreen["hiscore-1"].name.embedFonts = true;
- _parent.hiscorescreen["hiscore-1"].name.setTextFormat(myformat1);
- _parent.hiscorescreen["hiscore-1"].name.embedFonts = true;
- _parent.hiscorescreen["hiscore-1"].score.text = score;
- myformat1 = _parent.hiscorescreen["hiscore-1"].score.getTextFormat();
- myformat1.color = 65535;
- _parent.hiscorescreen["hiscore-1"].score.embedFonts = true;
- _parent.hiscorescreen["hiscore-1"].score.setTextFormat(myformat1);
- _parent.hiscorescreen["hiscore-1"].score.embedFonts = true;
- _parent.gamestate = GAMESTATE_GAME_OVER;
- timeinstate = 0;
- }
- }
-